﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using wdss.WebServices;

namespace wdss.GUI
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
            Response.Expires = -1500;
            Response.CacheControl = "no-cache";
            username_lbl.Text = (string)Session["username"];
            username_lbl.Visible = true;
        }

        protected void changePass_Click(object sender, EventArgs e)
        {
            string username = (string)Session["username"];
            string oldPassword = oldPass.Text;
            string newPassword = newPass.Text;
            string confirmPassword = confirmPass.Text;
            LogService log = new LogService();

            log.LogAction("Password changed request has been submitted by " + username);

            ChangePasswordService cps = new ChangePasswordService();
            bool success = cps.ChangePassword(username,oldPassword, newPassword, confirmPassword);
            if (success)
            {

                log.LogAction("Password changed for user: " + username);
                HttpContext.Current.Response.Write("<script>alert('Password has been changed!! ')</script>");

            }
            else 
            {
                log.LogAction("Password not changed for user: " + (string)Session["username"]);
                HttpContext.Current.Response.Write("<script>alert('Password could not be changed!! ')</script>");
            }

        }
    }
}
